
public class ThreadDemo7 {
    //随便创建一个Object变量
    static Object object =new Object();
    static Object object1 =new Object();
    static int sum =0;
    public static void main(String[] args) throws InterruptedException {

       Thread t = new Thread(() ->{
            for (int i = 0; i < 50000; i++) {
           synchronized (object) {
               synchronized (object) {
                   sum++;
               }
           }

            }
        });
        Thread t1 = new Thread(() ->{
            for (int i = 0; i < 50000; i++) {
                synchronized (object) {
                    sum++;
                }
            }
        });
        t.start();
        t1.start();
        t.join();
        t1.join();
        //这里预期应该是100000
        System.out.println(sum);

    }
}
